So in today's lesson we are going to learn about values.
Okay.
Now obviously you already know the different types of value.
You know about booleans.
You know about color three.
We looked about a lot earlier on in the course.
But today we're going to look at the physical objects that allow you to put these values into your game
okay.
So hover over and click the plus by the workspace okay.
And search up value.
And you'll see here we have a lot of different types of values.
We have booleans all the way down to vector threes now.
You should know most of these already.
Okay.
Booleans.
You should know brick colors.
You should know integers, numbers, all that kind of stuff.
There will be a couple here which you will not understand just yet, namely the C frame value and the
array value as well.
All the other ones you should know about.
So we're not going to look at those.
We might touch on those later on in the course, most likely in the Advanced scripting section okay.
But you will understand those later on.
We're not going to be looking at them yet today.
Okay.
So let's add in the boolean value.
Okay.
Let's click on it.
And these are the properties of the boolean value.
So it's just a name and it has a value.
So for boolean obviously it will be true or false.
If you add in a color free value um you can put in whatever color a vector free value you can put in
three numbers and so on.
So you can think of it as a variable which you can add into your game.
Okay.
Because it has a name and it has a value instead, but instead it has a parent and you can actually
reference it, um, as a normal method that you would use to reference things.
Okay.
So we could call this for example, um has VIP.
If I can get my caps correctly.
So one use for values is when you want to check something quite frequently.
So for example this here I've called it has VIP, perhaps because there is a VIP game pass which unlocks
certain things in your game, like it unlocks a new room, or it gives a player some benefits or things
like that.
Okay, if they don't have the VIP, they can't access those benefits, but if they do, obviously they
can access all of those.
Now, it'd be a good idea actually to add in a value for each player.
Okay, so then you can easily check if that player has VIP by checking this value instead of having
to check it a different way, which again, we'll learn about game passes and stuff later on, but this
way you'll be quicker to look at it.
Um, and it's also especially useful if you want to check check it from multiple scripts.
So that might be the case.
You know, there might be custom custom weapons or custom areas.
All will be including different scripts.
It won't be all in one script.
So um, a variables are great, but because you can't use them in multiple scripts or you can't just
yet.
Okay.
Um, values are a great addition to make instead.
Okay.
And they are actually essential for, um, certain things on the leaderboard.
Okay.
So when you play the game, um, a leaderboard will appear on the top left of your screen.
Okay.
You can see here.
Now currently this leaderboard is blank.
It just has my name.
But you can put other values on here okay.
Um a lot of games have some kind of currency.
So whether that's cash coins, diamonds anything very common for games okay.
And that's that, that value.
Um well that, that currency value that you have is going to be used a lot for shops for maybe a daily
reward system, all that kind of stuff.
Okay.
So it's a good idea to make it as a value, not as a variable.
So it can be accessed from multiple scripts.
And that's what we're going to do okay.
We're going to learn about how to add values onto the leaderboard so that other players can see one,
how many diamonds or whatever currency they have themselves, and also how many they have other players
and how they compare.
Okay.
And this, to be honest, is the biggest use for values.
Okay.
There are still absolutely used elsewhere, but um, all games or the majority of games need a currency
system.
So this is quite a very commonly used script for games.
Okay.
So add a server script into server script service.
Okay.
And um, we need to basically add some values into the leaderboard.
Okay.
Now um, this will happen when the player joins the game okay.
Because when the player joins the game we need to add their own values onto the leaderboard.
So um, funnily enough, we're going to be using the player added event, which we learned last lesson.
So let's write that out.
We have game dot players dot player added colon connect function player.
Now we don't need to worry about we don't need to worry about referencing the character because this
doesn't have anything to do with the character.
Okay, so how can we add stuff onto the leaderboard?
Well, it's quite simple, but a bit strange.
Okay, um, you might think already we can't add a value, um, into the workspace because otherwise
it wouldn't be that great because you would have.
If there's 30 players, you'd have 30 different values are quite difficult to tell whose value is whose,
and this is a bit difficult to work with.
Okay.
So instead we put the values inside of the player.
Okay.
Um, but the specific thing you need to do to that value in order for, um, Roblox to know that you
want to put it in the leaderboard.
Basically, you need to put it in the folder with the name Leaderstats.
Okay.
It's a very specific name.
Um, but when you put a folder inside your player just like this, um, sorry, just like this called
Leaderstats, any values you put inside there will be will be put onto the leaderboard.
Okay, obviously only some can be put on the leaderboard.
You can't put a object value or a color value onto the leaderboard, but there are some that you can
put on such.
As the values we're going to look having look having a look at today okay.
So that's what we're going to have to do.
Um but in scripting ways okay.
So we're going to use instance dot new for this.
So I hope you start to see how everything we've kind of learned in the last few lessons is kind of adding
in together.
You know, we're using events.
Um, now now we're using instance dot new to add in a value which we learned last lesson.
It all kind of comes together a bit in these next lessons.
So let's reference this Leaderstats folder.
Is equal to instance dot new folder.
Okay we're adding a new folder in and we're going to put it inside of the player.
Okay.
So it's specific to the player.
And it's much easier to tell whose is whose.
Okay.
Now Leaderstats you need to give it this specific name.
Okay.
Has to be leaderstats with a lowercase um a lowercase l.
If you give an if you give it an uppercase L, it will not work.
It has to be written exactly like that.
The name of the variable doesn't matter, but it's this thing that it needs to be exact.
Okay.
Because robots picks up on this name and it understands that anything inside that will be put onto the
leaderboard for any other name, it won't be able to assume that.
Okay.
So this is kind of one of the cases where where Roblox will actually assume something that you've done.
Um, I'm not too sure why they chose to do it this way.
It is a bit strange.
I think it would make a bit more sense if there was a thing in the explorer for it, but there you go.
Not things don't always make 100% sense.
Um, so now we've got a leaderstats.
The leaderstats folder into the player.
We now need to add a value inside of that.
I'm going to add a cash value.
But of course if you're wanting to add a different kind of currency it would work to the exact same.
So let's say local cash is equal to and we're going to add in a value.
Okay.
Now there are two types of values that include numbers.
That's an integer value and a number value.
Now right at the start of the scripting section I explain the difference between the two.
You probably don't remember it was a while ago.
Basically, an integer value can only accept whole numbers, whereas a number value can accept decimal
points.
So 0.1 or 5.7 for example.
Integer values only numbers like five, nine, 25, for example.
Okay, so for cash, um, which one would it make sense to use?
Obviously it'd be makes sense to use the integer value because you can't really have decimal points
for cash.
And it also makes calculating things a bit more difficult.
Sometimes it's easier just to use, um, plain numbers instead of things with decimal points.
Okay.
So we're going to use an integer value for this.
So we're going to add in an int value.
And we're going to parent it to Leaderstats not to the player to Leaderstats to go inside of that folder.
Okay.
From here we need to give it a name.
Cash dot name is equal to call it whatever you want.
It's not specific this time, so I'm just going to call it cash.
And then if you'd like to as well you can give it a starting value.
So remember when we added it in um integer value it has a property called value.
That's what we'd change.
The change the value of how much cash we have basically.
Okay.
So we can say cash dot value.
That's that's the property.
Okay.
And we're going to give it 50.
So to start off with when the player first joins they get 50 cash to start off with.
Okay.
And we can go ahead and play the game and see what happens on the leaderboard.
You can see here it looks a bit different.
Now I've got my name here.
I've got a little label here saying cash and say I've got here, I've got 50 cash available to spend.
Okay.
Obviously you can't spend it properly.
You need to code that.
But it's just the very basic leader stat system for that.
Okay.
And you can add as many integer values or other values as you like okay.
I don't believe all of them work.
I know int values do 100% work.
I believe other ones won't like colour free for example, but try them out.
Maybe some of them might might work.
I'm not too sure.
Um, but yeah, that's a key example on how values are used and the most commonly used case for values.
Okay.
And but remember that when you are coding things and maybe there's a key value, um, or a key bit of
data that you weren't going to want to refer to in a couple of other scripts, it might be a good idea
to use a value for it.
Okay, so have a play around with that, okay.
As they're quite new.
Um, and they'll really help you out when you are coding things, especially transferring data between
scripts.
Okay.
And join me.
Next lesson.
We're going to again apply our knowledge in a different area.
We're going to have a look at GIS.
Okay.
So I'll see you in the next lesson.